package br.com.fiaproupas.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.fiaproupas.model.Cliente;
import br.com.fiaproupas.util.RetornaJson;
import br.com.fiaproupas.util.RetornaLista;

/**
 * Servlet implementation class ListaClientesServlet
 */
@WebServlet("/listaClientesServlet")
public class ListaClientesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ListaClientesServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RetornaJson retornaJson = new RetornaJson();
		String clienteS = retornaJson.retornaJsonClientes();
		
		RetornaLista retornaLista = new RetornaLista();
		List<Cliente> clientes = retornaLista.buscaClientes(clienteS);
		
	    request.getSession().setAttribute("clientes", clientes);
	    
	    request.getRequestDispatcher("listaclientes.jsp").forward(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}
}
